﻿using System;
using Medianamik.Core.Security;
using System.Web;
using Medianamik.Core.Interfaces;

namespace Medianamik.Core
{
    /// <summary>
    /// Classe représentant une page de Médianamik
    /// </summary>
    public class MedianamikPage : SystemNode<MedianamikPage>
    {
        #region .ctors

        public MedianamikPage()
            : base()
        {

        }

        #endregion

        #region Properties

        #region ISystemNode Members

        public override Guid SystemNodeTypeID
        {
            get { return MedianamikTypes.MedianamikPage; }
        }

        #endregion

		public override string DisplayName
		{
			get
			{
				return (string)HttpContext.GetGlobalResourceObject("SiteMap", FileName);
			}
		}
                

        #region Language Neutral Properties
                    

        public new bool IsLanguageNeutral
        {
            get
            {
                return DefaultInstance.Properties["IsLanguageNeutral"].GetValue<bool>();
            }
            set
            {
                DefaultInstance.Properties["IsLanguageNeutral"].SetValue(value);
            }
        }

        public bool DisplayInMenu
        {
            get
            {
                return DefaultInstance.Properties["DisplayInMenu"].GetValue<bool>();
            }
            set
            {
                DefaultInstance.Properties["DisplayInMenu"].SetValue(value);
            }
        }

        public bool IsEditionPage
        {
            get
            {
                return DefaultInstance.Properties["IsEditionPage"].GetValue<bool>();
            }
            set
            {
                DefaultInstance.Properties["IsEditionPage"].SetValue(value);
            }
        }

        public string FileName
        {
            get
            {
                return DefaultInstance.Properties["FileName"].GetValue<string>();
            }
            set
            {
                DefaultInstance.Properties["FileName"].SetValue(value);
            }
        }

        public Guid? ModuleId
        {
            get
            {
                return DefaultInstance.Properties["Module"].GetValue<Guid?>();
            }
            set
            {
                DefaultInstance.Properties["Module"].SetValue(value);
            }
        }

        public MedianamikModule Module
        {
            get
            {
                if (_module == null)
                {
                    _module = ModuleId.HasValue
                    ? ConfigManager.Get<MedianamikModule>(ModuleId.Value)
                    : default(MedianamikModule);
                }

                if (_module != default(MedianamikModule))
                    _module.DefaultCulture = DefaultCulture;

                return _module;
            }
        }
        private MedianamikModule _module;

		public Guid?  MenuGroupId
		{
			get
			{
				return DefaultInstance.Properties["MenuGroup"].GetValue<Guid?>();
			}
			set
			{
				DefaultInstance.Properties["MenuGroup"].SetValue(value);
			}
		}

		public MenuGroup GetMenuGroup()
		{
			return MenuGroupId.HasValue
			? ConfigManager.Get<MenuGroup>(MenuGroupId.Value)
			: default(MenuGroup);
		}

		

		public IRole[] GetRoles()
		{
            return SecurityManager.GetRolesForPage(this);
		}


        #endregion

        #endregion

        #region Methods

	

        #endregion
    }
}
